import Register from '../modules/register.js';
import Login from '../modules/login.js';
import Manage from '../modules/manage.js';
import Student from '../modules/student/student.js';
import Cls from '../modules/class/class.js';
import Course from '../modules/course/course.js';
import Cinema from '../modules/cinema/cinema.js';
import Router from './director.js';


let routes = {
    '/register':() => new Register(),
    '/login':() => new Login(),
    '/manage':{
        '/student': () => new Student(),
        '/class': () => new Cls(),
        '/course':() => new Course(),
        '/cinema':() => new Cinema(),
        on:(next) => new Manage(next)
    }
};
const $ = layui.$;
// 每次ajax请求都会将token信息从localStorage中取出并设置到请求头中
$.ajaxSettings.beforeSend = function(xhr,request){
    // 在这里加上你的 token 
    xhr.setRequestHeader('Authorization','Bearer '+layui.data('tokens').token);
}

// 默认访问登录模块
location.hash = location.hash || "#login";
let router = Router(routes).configure({
    recurse: 'forward',
    async:true,// 需要手动控制后续模块的渲染
    strict:false
}); // 实例化路由
router.init(); // 初始化路由